import io.gitee.cengxiaoxiao.wrapper.ExcelFillWrapper;
import io.gitee.cengxiaoxiao.wrapper.ExcelReadWrapper;
import io.gitee.cengxiaoxiao.wrapper.ExcelWriteWrapper;
import org.apache.commons.lang3.RandomStringUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        fill();
    }

    public static void write() {
        List<ExcelData> data = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            String name = String.format("%s%s", "小明", RandomStringUtils.insecure().nextAlphabetic(8));
            String phone = RandomStringUtils.insecure().next(11, false, true);
            data.add(new ExcelData((long) i, name, phone, LocalDate.now(),
                    LocalTime.now(), LocalDateTime.now(), BigDecimal.valueOf(22.22), 11.11, "男"));
        }
        File file = new File("D:\\test.xlsx");
        try {
            FileOutputStream fos = new FileOutputStream(file);
            ExcelWriteWrapper.write(fos, ExcelData.class, data);
            fos.flush();
            fos.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static List<ExcelData> read() {
        File file = new File("D:\\test.xlsx");
        try (FileInputStream inputStream = new FileInputStream(file)) {
            return ExcelReadWrapper.read(inputStream, ExcelData.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void fill() {
        File file = new File("D:\\填充实例.xlsx");
        List<ExcelData> list = read();
        try (FileOutputStream outputStream = new FileOutputStream(file)) {
            ExcelFillWrapper.fill(outputStream, list, "D:\\ideaProject\\jxhlw_official\\src\\main\\resources\\templates\\填充模板.xlsx");
            outputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}